<template>
  <div class="goodsData">

    <el-card class="card">

      <div slot="header" class="clearfix entry">
        <h3 class="title">商品数据</h3>
        <div>
          <el-date-picker v-model="dateValue" type="daterange" range-separator="至" ref="datePicker"
            start-placeholder="开始日期" end-placeholder="结束日期" @change="changePicker">
          </el-date-picker>
          <el-button @click="recentSevenDay">近7天</el-button>
          <el-button @click="recentThirtyDay">近30天</el-button>
          <el-button @click="custom">自定义</el-button>
        </div>
      </div>

      <div class="goodsList">
        <div>
          <h4>浏览Top榜</h4>
          <div v-for="(i,j) in browseList" :key="i.id" class="item">
            <img :src="i.original" alt="" />
            <div>
              <p><span>Top{{j+1}}</span><span>{{i.num}}</span></p>
              <p>{{i.goodsName}}</p>
              <p><span>商品编号：</span><span>{{i.identifier}}</span></p>
              <p><span>原价：</span><span>￥{{i.price}}</span></p>
              <p></p>
            </div>
          </div>
        </div>
        <div>
          <h4>热销Top榜</h4>
          <div v-for="i in hotSellingList" :key="i.id" class="item">
            <img :src="i.original" alt="" />
            <div>
              <p><span>Top{{j+1}}</span><span>{{i.num}}</span></p>
              <p>{{i.goodsName}}</p>
              <p><span>商品编号：</span><span>{{i.identifier}}</span></p>
              <p><span>原价：</span><span>￥{{i.price}}</span></p>
              <p></p>
            </div>
          </div>
        </div>
      </div>

    </el-card>

  </div>
</template>

<script>
import { getHotSellingList, getBrowseList } from '@/api/statisticsAdmin/goodsSale.js'

export default {
  name: "GoodsSkuSaleStatistics",
  data () {
    return {
      dateValue: [],
      browseList: [{ id: 1, goodsName: '商品名称', imgUrl: '123', price: '123' }],
      hotSellingList: [{ id: 1, goodsName: '商品名称', imgUrl: '123', price: '123' }],
      startDate: '',
      endDate: '',
      parameters: { limit: 50, startDate: '', endDate: '' },
    }
  },
  created () {
    this.recentDay(0)
    // this.recentSevenDay()
  },
  methods: {
    getList () {
      getBrowseList(this.parameters).then(res => {
        this.browseList = res.data
      })
      getHotSellingList(this.parameters).then(res => {
        this.hotSellingList = res.data
      })
    },
    changePicker (e) {
      this.parameters.startDate = this.parseTime(e[0], '{y}-{m}-{d}')
      this.parameters.endDate = this.parseTime(e[1], '{y}-{m}-{d}')
      this.getList()
    },
    recentSevenDay () {
      this.recentDay(6)
    },
    recentThirtyDay () {
      this.recentDay(29)
    },
    recentDay (day) {
      let start = new Date()
      let end = new Date()
      start.setDate(start.getDate() - day)
      this.parameters.startDate = this.parseTime(start, '{y}-{m}-{d}')
      this.parameters.endDate = this.parseTime(end, '{y}-{m}-{d}')
      this.dateValue = [start, end]
      this.getList()
    },
    custom () {
      this.$refs.datePicker.focus()
    },
  },

}
</script>

<style lang="scss" scoped>
.goodsData {
  padding: 10px;
  .card {
    padding: 20px;
    ::v-deep .el-card__header {
      padding: 0;
    }
    .clearfix {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    ::v-deep .el-button {
      margin-left: 10px;
    }

    .goodsList {
      width: 100%;
      max-height: 50%;
      display: flex;
      justify-content: space-around;
      h4 {
        display: flex;
        align-items: center;
      }
      h4::before {
        content: "";
        display: block;
        width: 3px;
        height: 10px;
        background: #266cf0;
        margin-right: 5px;
      }
      .item {
        display: flex;
        img {
          width: 100px;
          height: 100px;
          border-radius: 4px;
          margin-right: 5px;
        }
        p {
          line-height: 1;
          margin: 0;
          margin-bottom: 7%;
          font-size: 14px;
        }
        $color: rgba(
          $color: rgb(248, 203, 55),
          $alpha: 1,
        );
        p:nth-child(1) {
          font-size: 12px;
          margin-top: 4px;
          margin-bottom: 8%;
          span {
            padding: 1px 4px;
          }
          span:nth-child(1) {
            color: #fff;
            border-radius: 4px 0 0 4px;
            background: $color;
            border: 1px solid $color;
          }
          span:nth-child(2) {
            border-radius: 0 4px 4px 0;
            color: $color;
            border: 1px solid $color;
          }
        }
        p:nth-child(2) {
        }
        p:nth-child(3) {
        }
        p:nth-child(4) {
        }
      }
    }
  }
}
</style>
